/* eslint-disable vue/require-default-prop */

<template>
  <div>
    <el-dialog title="提交审核" :visible.sync="visibleDialog" width="20%">
      <el-form ref="auditFrom" :model="auditFrom" label-width="100px">
        <!-- <el-form-item label="审核意见">
          <el-radio v-model="auditFrom.result" label="1">通过</el-radio>
          <el-radio v-model="auditFrom.result" label="2">不通过</el-radio>
        </el-form-item> -->
        <el-form-item label="申请原因" prop="auditComment">
          <el-input v-model="auditFrom.opinion" />
        </el-form-item>
        <el-form-item label="处理人" prop="auditComment">
          <el-tag v-if="trainName.length > 0">{{ trainName[0].label }}</el-tag>
          <el-button
            size="mini"
            round
            circle
            icon="el-icon-plus"
            @click="openReview()"
          />
        </el-form-item>
        <el-form-item>
          <span>
            <el-button @click="visible = false">取 消</el-button>
            <el-button type="primary" @click="setAuditStatus">确 定</el-button>
          </span></el-form-item
        >
      </el-form>
    </el-dialog>
    <SearchPersonnel
      :search-personnel-data="SearchPersonnelData"
      @dataListData="dataListData"
    />
  </div>
</template>

<script>
import { auditCommonFlowApplyBom } from '@/api/base/bom'
import SearchPersonnel from '@/components/SearchUser/SearchPersonnel.vue'
export default {
  components: { SearchPersonnel },
  props: {
    visible: {
      required: false,
      type: Boolean
    },
    dialogStatus: {
      require: true,
      type: String,
      default: 'bom'
    },
    currentRow: {
      require: true,
      type: Object,
      default: null
    },
    updateData: {
      type: Function,
      default: () => {}
    }
  },
  data() {
    return {
      auditFrom: { result: '1', opinion: '' },
      rules: {
        auditComment: [
          { required: true, message: '意见不能为空', trigger: 'blur' }
        ]
      },
      SearchPersonnelData: {},
      trainName: []
    }
  },
  computed: {
    visibleDialog: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },
  watch: {
    currentRow: {
      handler(row) {
        this.auditFrom = row
        this.auditFrom.auditStatus = '1'
      },
      deep: true
    }
  },
  mounted() {},
  methods: {
    setAuditStatus() {
      let data = {}
      if (this.dialogStatus === 'bom') {
        this.$refs['auditFrom'].validate((valid) => {
          if (valid) {
            data = {
              businessId: this.currentRow.bomId,
              bizType: 3,
              flowType: 1,
              handleUserId: this.trainName[0].id,
              opinion: this.auditFrom.opinion,
              urgent: '0'
            }
          }
        })
      } else {
        this.$refs['auditFrom'].validate((valid) => {
          if (valid) {
            data = {
              businessId: this.currentRow.bomId,
              bizType: 4,
              handleUserId: this.trainName[0].id,
              opinion: this.auditFrom.opinion,
              urgent: '0'
            }
          }
        })
      }
      auditCommonFlowApplyBom(data).then((res) => {
        this.$message.success('操作成功')
        this.$emit('update-data')
      })
    },
    openReview() {
      this.SearchPersonnelData = {
        dialogVisible: true
      }
    },
    dataListData(data) {
      if (data) {
        this.trainName = data || []
      }
    }
  }
}
</script>

<style>
.a {
  position: absolute;
}
</style>
